<template>
	<view class="container">
		<view style="height: var(--status-bar-height);"></view>
		<view class="top">
			<u-sticky bgColor="#fff">
				<u-tabs :current="tabIndex" :list="typeList" @click="tabClick" lineWidth="30" lineColor="#ffce45"
					:activeStyle="{
				            color: '#303133',
				            fontWeight: 'bold',
				            transform: 'scale(1.5)'
				        }" :inactiveStyle="{
				            color: '#606266',
				            transform: 'scale(1.2)'
				        }" itemStyle="padding-left: 15px; padding-right: 15px; height: 34px;">
				</u-tabs>
			</u-sticky>
		</view>
		<!-- --------- -->
		<view class="vodContent">
			<view v-for="item,index in vodList" :key="index" @click="itemClick(item.vod_id)"
				style="display: flex;flex-direction: row;margin-top: 10px; border: 1px solid #ffce45;width: 100%;height: 160px;border-radius: 10px;">
				<view class="img" style="margin: 5px 5px 10px 10px;">
					<image style="height: 150px;width: 110px;border-radius: 6px;object-fit: cover;" :src="item.vod_pic">
					</image>
				</view>
				<view class="introduce"
					style="width: 100%;display: flex;flex-direction: column;margin: 5px 5px 10px 10px;">
					<text
						style="font-size: 17px;font-weight: bold; width: 200px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">{{item.vod_name}}</text>
					<view style="margin-top: 15px;display: flex;flex-direction: row;">
						<u-rate readonly size="22" :value="parseFloat(item.vod_douban_score)/2" active-color="#ffce45"
							inactive-color="#b2b2b2"></u-rate>
						<text style="color: #76797d;">{{item.vod_douban_score}}</text>
					</view>
					<text
						style="display:inline-block; word-wrap: break-word;margin-top: 15px;color: #76797d;font-size: 10px;height: 40px; width: 200px;overflow: hidden;text-overflow: ellipsis;">
						{{item.vod_blurb}}
					</text>
					<view
						style="margin:10px 0px 0px 0px;font-size: 10px;color: #76797d;width: 50px;height: 19px;border-radius: 5px;background-color: #e8edf3;text-align: center;">
						<text>{{item.vod_year}}年</text>
					</view>
				</view>
			</view>
			<u-loadmore :status="status" />
		</view>
	</view>
</template>

<script>
	import {
		http
	} from '@/config/common.js'
	export default {
		data() {
			return {
				page: 1,
				size: 10,
				type: '片',
				totalPage: 0,
				tabIndex: 0,
				status: 'loadmore',
				vodList: [],
				typeList: [{
					name: '电影'
				}, {
					name: '动漫'
				}, {
					name: '综艺'
				}, {
					name: '电视剧'
				}, {
					name: '纪录片'
				}],
			}
		},
		onLoad(res) {
			//res.tabIndex
			console.log(res);
			if (res.tabIndex != null) {
				this.tabIndex = res.tabIndex;
				this.type = res.type;
			}
		},
		onShow() {
			this.getVods();
		},
		//加载更多
		onReachBottom() {
			if (this.page >= this.totalPage) {
				this.status = 'nomore';
				return;
			}
			this.status = 'loading';
			this.page = ++this.page;
			this.getVods();
			setTimeout(() => {
				if (this.page >= this.totalPage) this.status = 'nomore';
				else this.status = 'loading';
			}, 2000)
		},
		methods: {
			getVods() {
				http.get('/vod/leaderboard/' + this.type + '/' + this.page + '/' + this.size, {}).then(res => {
					const data = res.data.data;
					console.log(data)
					this.totalPage = data.pages;
					if (this.vodList.length > 0) {
						var list = data.records;
						for (var i = 0; i < list.length; i++) {
							this.vodList.push(list[i]);
						}
					} else {
						this.vodList = data.records;
					}
				}).catch(err => {
					console.log(err)
				})
			},
			tabClick(item) {
				console.log('item', item);
				if (item.name === "电影") {
					this.type = '片';
				} else if (item.name === "电视剧") {
					this.type = '剧';
				} else {
					this.type = item.name;
				}
				this.page = 1;
				this.vodList = [];
				this.getVods();
			},
			itemClick(data) {
				//data：vodId
				uni.navigateTo({
					url: '/pages/video/video?vodId=' + data,

				})
			}
		}
	}
</script>

<style>
	.vodContent {
		display: flex;
		flex-direction: column;
		width: 94%;
		margin: 0 0 10px 10px;
	}
</style>